package edu.arizona.sista.learn.model.groups;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import edu.arizona.sista.learn.model.ParamInterval;

/**
 * A simple model for a person, which is a "thing".
 * 
 * @author Anh Tran
 *
 */
public class Person extends Thing {
	
	// Look-at information.
	private List<ParamInterval<Thing>> _lookAt;
	
	// Gestures information.
	private List<ParamInterval<String>> _gestures;
	
	public Person(String name) {
		super(name);
		_lookAt = new ArrayList<ParamInterval<Thing>>();
		_gestures = new ArrayList<ParamInterval<String>>();
	}
	
	/**
	 * Get the person's lookAt information.
	 * @return The person's lookAt information.
	 */
	public List<ParamInterval<Thing>> lookAt() {
		return _lookAt;
	}
	
	/**
	 * Add a new look-at interval.
	 */
	public void addLookingInterval(ParamInterval<Thing> i) {
		_lookAt.add(i);
		Collections.sort(_lookAt);
	}

	/**
	 * Get the targets that the actor is currently looking
	 * at for the given timestep.
	 * @param timeStep The timestep.
	 * @return The targets that the actor is looking at,
	 * or null if the person is not looking at anyone.
	 */
	public Set<Thing> getLookAtTargets(int timeStep) {
		Set<Thing> targets = new HashSet<Thing>();
		for (ParamInterval<Thing> in : _lookAt) {
			if (in.interval().isOn(timeStep)) {
				targets.add(in.obj());
			}
		}
		return targets;
	}
	
	/**
	 * Get the person's gestures information.
	 * @return The person's gestures information.
	 */
	public List<ParamInterval<String>> gestures() {
		return _gestures;
	}
	
	/**
	 * Add a new gesture interval.
	 */
	public void addGestureInterval(ParamInterval<String> i) {
		_gestures.add(i);
		Collections.sort(_gestures);
	}

	public String toStringVerbose() {
		return "{" + this.id() + ":" + this.name() + "}"+
			" -> " + _lookAt.toString() + " || " + _gestures.toString();
	}
	
	public String toStringLookAt() {
		return "{" + this.id() + ":" + this.name() + "}"+
			" -> " + _lookAt.toString();
	}

	public String toStringGestures() {
		return "{" + this.id() + ":" + this.name() + "}"+
			" -> " + _gestures.toString();
	}
}
